home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / fclose.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  510 b   |  29 lines

  1.  
  2. /* fclose */
  3.  
  4. #include <file.h>
  5. #include "std-guts.h"
  6.  
  7. int fclose (f)
  8. struct file * f;
  9. {
  10.   if (f && f->open_p)
  11.     {
  12.     if (((f->mode & 0x03) == O_WRONLY) ||
  13.         ((f->mode & 0x03) == O_RDWR))
  14.         {
  15. /* see if buffer needs flushing */
  16.         int len = f->buf_max;
  17.  
  18.         if (len > 0)
  19.             write(f->handle, &f->buf, len);
  20.         f->buf_index = f->buf_max = 0;
  21.         }
  22.     if ((f->handle > 2) || (!isatty(f->handle)))
  23.         close(f->handle);
  24.     }
  25.   if (f)
  26.     free(f);
  27.   return(0);        /* really should check for err ... */
  28. }
  29.